<?php

require_once './WechatSys.php';
require_once './WechatCmd.php';

class WechatApp {
	function run() {
		if (isset($_GET["signature"]) && isset($_GET["timestamp"]) && isset($_GET["nonce"])) {
			$wechatObj = new WechatSys();
			if (isset($_GET["echostr"])) {
				$wechatObj->valid();
			} else if($wechatObj->checkSignature()) {
				$wechatObj->responseMsg();
			}
		} else if (isset($_GET['r'])) {
			$wechatObj = new WechatCmd();
			$cmd = $_GET["r"];
			
			switch ($cmd) {
				case "redirect":
					$wechatObj->redirect();
					break;
				case "rediWithId":
					$wechatObj->redirectReal();
					break;
				default:
			}
			return;
		}
	}
}
?>